#include "scheduler/delay_scheduler.h"
#include "../policy/behavior_tree/behavior_tree_delay_policy.h"
#include "../policy/policy_factory.h"

namespace scheduler
{
DelayScheduler::DelayScheduler(const std::string &name)
    : AbstractScheduler(name)
{
    schedule_policy_ = policy::PolicyFactory<policy::BehaviorTreeDelayPolicy>::createPolicy(name);
}
DelayScheduler::DelayScheduler(const std::string &name, int delay_mill_second)
    : AbstractScheduler(name)
{
    schedule_policy_ = policy::PolicyFactory<policy::BehaviorTreeDelayPolicy>::createPolicy(name, delay_mill_second);
}
bool DelayScheduler::appendTask(const task::AbstractTaskConstPtr &task)
{
    EASE_ERROR("delay scheduler cannot add task");
    throw std::runtime_error("delay scheduler cannot add task");
}
bool DelayScheduler::appendScheduler(const AbstractSchedulerConstPtr &scheduler)
{
    EASE_ERROR("delay scheduler cannot add scheduler");
    throw std::runtime_error("delay scheduler cannot add scheduler");
}
void DelayScheduler::setDelayTime(uint32_t milli_second)
{
    auto *policy = dynamic_cast<policy::BehaviorTreeDelayPolicy *>(schedule_policy_.get());
    if (nullptr == policy)
    {
        throw std::runtime_error("delay scheduler policy case fail");
    }
    policy->setDelayMilliSecond(milli_second);
}
DelayScheduler::~DelayScheduler() = default;
}
